package com.arpa.oms.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.arpa.core.web.MediaTypes;
import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.exception.ServiceException;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.common.util.excel.EasyExcelUtil;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.wms.domain.consts.PropertyConst;
import com.arpa.wms.domain.dto.GoodsUnitDTO;
import com.arpa.wms.domain.dto.GoodsUnitExcelDTO;
import com.arpa.wms.domain.entity.GoodsUnit;
import com.arpa.wms.domain.enums.StatusEnum;
import com.arpa.wms.domain.vo.GoodsUnitExcelVO;
import com.arpa.wms.domain.vo.UnitVO;
import com.arpa.wms.service.IGoodsUnitService;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * Oms单位 Controller
 * </p>
 *
 * @author wangdong
 * @since 2021-07-21
 */

@Api(tags = "单位")
@RestController
@RequestMapping(value = "/omsGoodsUnit", produces = "application/json;charset=UTF-8")
@Log4j2
public class OmsGoodsUnitController {

    private final IGoodsUnitService iGoodsUnitService;

    public OmsGoodsUnitController(IGoodsUnitService iGoodsUnitService) {
        this.iGoodsUnitService = iGoodsUnitService;
    }

    @ApiOperation(value = "商品单位列表", notes = "单位单位列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = UnitVO.class))
    @NeedLogin
    @GetMapping
    public Result list(GoodsUnitDTO unitDTO, HttpServletRequest request) {
        try {
            unitDTO.setShipmentCode(UserUtil.getLoginWarehouseCodeOrShipmentCode());
            UnitVO unitSum = iGoodsUnitService.queryListSum(unitDTO);
            List<UnitVO> unitVOList = iGoodsUnitService.queryList(unitDTO);

            Page returnPage = new Page(unitDTO.getPageNum(), unitDTO.getPageSize());
            returnPage.setRecords(unitVOList);
            returnPage.setTotal(unitSum.getTotal());
            returnPage.setSumObject(unitSum);
            return Result.ok().data(returnPage);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }

}
